package cn.stronglink.assetmanage.business.inspection.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.check.adapter.CheckOrderAdapter;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.RepailDetail;
import cn.stronglink.assetmanage.index.view.onRecyclerListener;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * 维修登记资产列表
 * Created by zhengjinglan on 2018/6/21.
 */

public class RepairRegisterOrderApdapter  extends RecyclerView.Adapter<RepairRegisterOrderApdapter.ViewHolder> {
    private Context mContext;
    private List<Asset> datas;
    private onRecyclerListener listener;

    public RepairRegisterOrderApdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public RepairRegisterOrderApdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_repair_datail, null);
        return new RepairRegisterOrderApdapter.ViewHolder(view, listener);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Asset asset = datas.get(position);
        holder.bindRepo(asset, position);
    }


    @Override
    public int getItemCount() {

        return datas == null ? 0 : datas.size();
    }

    public void setOnItemClickListener(onRecyclerListener listener) {
        this.listener = listener;
    }

    public void notifyDatasChanged(List<Asset> data) {
        this.datas = data;
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        private TextView tv_check_wait_asset_name,tv_status;
        private TextView tv_check_wait_sn;
        private LinearLayout linearLayout;
        private onRecyclerListener listener;

        public ViewHolder(View itemView, onRecyclerListener listener) {
            super(itemView);
            this.listener = listener;
            tv_check_wait_asset_name = (TextView)itemView.findViewById(R.id.tv_check_asset_name);
            //sn号
            tv_check_wait_sn = (TextView)itemView.findViewById(R.id.tv_repair_rfid_no);
            linearLayout = (LinearLayout) itemView.findViewById(R.id.ll_repair_detail);
            tv_status=itemView.findViewById(R.id.tv_status);
        }

        public void bindRepo(Asset repo, int position) {
            tv_check_wait_asset_name.setText(repo.getAssetName());
            tv_check_wait_sn.setText(repo.getSerialNo());
            linearLayout.setOnClickListener(this);
            int bindStatus = repo.getStatus();

            if (bindStatus == Constants.STATUS_THREE) {
                tv_status.setText(mContext.getResources().getString(R.string.common_binded));
                tv_status.setTextColor(mContext.getResources().getColor(R.color.bind_green));
            } else {


                tv_status.setText(mContext.getResources().getString(R.string.common_unbind));
                tv_status.setTextColor(mContext.getResources().getColor(R.color.un_bind_red));
            }


        }

        @Override
        public void onClick(View v) {
            if (listener != null) {
                listener.onItemClicked(v, getAdapterPosition());
            }
        }
    }
}
